<div class="parent">
    <div class="child">测试示例</div>
  </div>
  <style>
    .parent {
      height: 100px;
      background-color: aqua;

      position:relative;
    }
    .child {
      background-color: blueviolet;

      position: absolute;
      left:50%;
      top:50px;
      transform: translate(-50%,-50%);
    }
  </style>